package com.cdut.drivingschool.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.cdut.drivingschool.bean.BaseType;
import com.cdut.drivingschool.bean.Group;
/**
 * 数据适配器基类
 * @author Administrator
 *
 * @param <T>
 */
public abstract class BaseGroupAdapter<T extends BaseType> extends BaseAdapter{
	private Context mContext;
	private Group<T> group;
	public BaseGroupAdapter(Context context) {
		this.mContext = context;
		group = new Group<T>();
	}
	/**
	 * 设置数据源
	 */
	public void setGroup(Group<T> group){
		this.group = group;
		this.notifyDataSetChanged();
	}
	/**
	 * 添加数据
	 */
	public void addData(T data){
		group.add(data);
		this.notifyDataSetChanged();
	}
	/**
	 *移出数据
	 */
	public void removeData(T data){
		group.remove(data);
		this.notifyDataSetChanged();
	}
	/**
	 * 添加数据集
	 */
	public void addGroup(Group<T> group){
		group.addAll(group);
	}
	/**
	 * 获取数据源
	 * @return
	 */
	public Group<T> getGroup(){
		return this.group;
	}
	public Context getContext(){
		return mContext;
	}
	@Override
	public int getCount() {
		return group.size();
	}

	@Override
	public Object getItem(int position) {
		return group.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	abstract public View getView(int position, View convertView, ViewGroup parent);

}
